<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bilibili 图标生成器</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            max-width: 800px;
            margin: 50px auto;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .container {
            background: rgba(255, 255, 255, 0.95);
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            color: #333;
        }
        h1 {
            color: #00A1D6;
            text-align: center;
            margin-bottom: 30px;
        }
        button {
            background: #00A1D6;
            color: white;
            border: none;
            padding: 15px 30px;
            font-size: 16px;
            font-weight: bold;
            border-radius: 8px;
            cursor: pointer;
            width: 100%;
            margin: 10px 0;
            transition: all 0.3s;
        }
        button:hover {
            background: #0087b3;
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 161, 214, 0.4);
        }
        .preview {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin: 30px 0;
            flex-wrap: wrap;
        }
        .preview-item {
            text-align: center;
        }
        .preview-item img {
            background: #f0f0f0;
            padding: 10px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        .info {
            background: #e3f2fd;
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
            border-left: 4px solid #00A1D6;
        }
        .success {
            background: #c8e6c9;
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
            border-left: 4px solid #4caf50;
            display: none;
        }
        canvas {
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎬 Bilibili 图标生成器</h1>
        
        <div class="info">
            <strong>说明：</strong><br>
            1. 点击"生成PNG图标"按钮，下载所有PNG格式图标<br>
            2. 访问 <a href="https://convertio.co/zh/png-ico/" target="_blank">https://convertio.co/zh/png-ico/</a> 上传 icon.png 转换为 icon.ico<br>
            3. 如果需要Mac图标，访问 <a href="https://cloudconvert.com/png-to-icns" target="_blank">https://cloudconvert.com/png-to-icns</a> 转换为 icon.icns<br>
            4. 将所有文件复制到 <code>src-tauri/icons/</code> 目录<br>
            5. 重新构建：<code>npm run tauri build</code>
        </div>

        <div class="preview">
            <div class="preview-item">
                <img id="preview-32" width="32" height="32">
                <div>32x32</div>
            </div>
            <div class="preview-item">
                <img id="preview-128" width="128" height="128">
                <div>128x128</div>
            </div>
            <div class="preview-item">
                <img id="preview-256" width="128" height="128">
                <div>256x256</div>
            </div>
        </div>

        <button onclick="generateAllIcons()">生成PNG图标（14个文件）</button>
        <button onclick="downloadSVG()" style="background: #667eea;">下载SVG源文件</button>
        
        <div id="success" class="success">
            ✅ 图标生成成功！请查看浏览器下载文件夹。
        </div>
    </div>

    <canvas id="canvas"></canvas>

    <script>
        const svgContent = `<?xml version="1.0" encoding="UTF-8"?>
<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
  <rect width="512" height="512" fill="#00A1D6" rx="80"/>
  <g transform="translate(256, 256)">
    <rect x="-110" y="-120" width="35" height="80" rx="17.5" fill="white"/>
    <rect x="75" y="-120" width="35" height="80" rx="17.5" fill="white"/>
    <rect x="-120" y="-50" width="240" height="180" rx="40" fill="white"/>
    <circle cx="-60" cy="0" r="25" fill="#00A1D6"/>
    <circle cx="60" cy="0" r="25" fill="#00A1D6"/>
    <path d="M -40 60 Q 0 80 40 60" stroke="#00A1D6" stroke-width="12" fill="none" stroke-linecap="round"/>
  </g>
</svg>`;

        function svgToPng(size, filename) {
            return new Promise((resolve) => {
                const canvas = document.getElementById('canvas');
                const ctx = canvas.getContext('2d');
                canvas.width = size;
                canvas.height = size;

                const img = new Image();
                const blob = new Blob([svgContent], { type: 'image/svg+xml' });
                const url = URL.createObjectURL(blob);

                img.onload = function() {
                    ctx.clearRect(0, 0, size, size);
                    ctx.drawImage(img, 0, 0, size, size);
                    
                    canvas.toBlob((blob) => {
                        const link = document.createElement('a');
                        link.download = filename;
                        link.href = URL.createObjectURL(blob);
                        link.click();
                        
                        // 更新预览
                        if (size === 32) {
                            document.getElementById('preview-32').src = canvas.toDataURL();
                        } else if (size === 128) {
                            document.getElementById('preview-128').src = canvas.toDataURL();
                        } else if (size === 256) {
                            document.getElementById('preview-256').src = canvas.toDataURL();
                        }
                        
                        URL.revokeObjectURL(url);
                        resolve();
                    }, 'image/png');
                };

                img.src = url;
            });
        }

        async function generateAllIcons() {
            const sizes = [
                { size: 32, name: '32x32.png' },
                { size: 128, name: '128x128.png' },
                { size: 256, name: '128x128@2x.png' },
                { size: 512, name: 'icon.png' },
                { size: 30, name: 'Square30x30Logo.png' },
                { size: 44, name: 'Square44x44Logo.png' },
                { size: 71, name: 'Square71x71Logo.png' },
                { size: 89, name: 'Square89x89Logo.png' },
                { size: 107, name: 'Square107x107Logo.png' },
                { size: 142, name: 'Square142x142Logo.png' },
                { size: 150, name: 'Square150x150Logo.png' },
                { size: 284, name: 'Square284x284Logo.png' },
                { size: 310, name: 'Square310x310Logo.png' },
                { size: 50, name: 'StoreLogo.png' }
            ];

            for (const { size, name } of sizes) {
                await svgToPng(size, name);
                await new Promise(resolve => setTimeout(resolve, 100));
            }

            document.getElementById('success').style.display = 'block';
            alert('PNG图标生成完成！\n\n接下来：\n1. 访问 https://convertio.co/zh/png-ico/ 上传 icon.png 转换为 icon.ico\n2. 将所有文件复制到 src-tauri/icons/\n3. 重新构建：npm run tauri build');
        }

        function downloadSVG() {
            const blob = new Blob([svgContent], { type: 'image/svg+xml' });
            const link = document.createElement('a');
            link.download = 'bilibili-icon.svg';
            link.href = URL.createObjectURL(blob);
            link.click();
        }

        // 页面加载时生成预览
        window.onload = function() {
            svgToPng(32, 'preview-32');
            svgToPng(128, 'preview-128');
            svgToPng(256, 'preview-256');
        };
    </script>
</body>
</html>

